%macro get_sched_d;


	
	proc printto log = "&logdir/get_sched_d.txt" new;
	run;
	
	proc sort data = rlib.filing_status(where=(prim_tin_x~=.)) out = unique nodupkey;
		by prim_tin_x;
	run;

	data _null_;
		set unique;
		file "&tmpdir/tinlist" dlm=',';
		put prim_tin_x;
	run;


	proc sql noprint;
		[connection details redacted]
			create table sample as
			select * from connection to iq 
		(
		select 
			a.prim_tin_x,
			coalesce(b.[redacted],0) as st_sched_d,
			coalesce(b.[redacted],0) as lt_sched_d,
			b.[redacted] as cp
		from #tinlist as a 
			inner join [redacted] as b 
				on(a.prim_tin_x = b.[redacted])
		where b.[redacted] = &base_yr-1
		order by a.prim_tin_x,
			cp
	);
	disconnect from iq;
	quit;


	data rlib.sched_d;
		set sample;
		by prim_tin_x;
		if last.prim_tin_x;
		
		drop cp;
		
	run;


	proc printto;
	run;

%mend;